const express = require('express');
const exStatic = require('express-static');
const cookieParser = require('cookie-parser');
const cookieSession = require('cookie-session');
const bodyParser = require('body-parser');
const multer = require('multer');
const consolidate = require('consolidate');
const ejs = require('ejs');
const jade = require('jade');

var server = express();
server.listen(3000);

/**
 * 1. 解析cookie
 */
server.use(cookieParser("12312jsadsdfasdf"));

/**
 * 2.使用session
 */
var arrKey=[];
for(var i = 0;i<1000;i++){
    arrKey.push("keys_#"+Math.random());
}
server.use(cookieSession({name:"key_sess_id",keys:arrKey,maxAge:20*3600*1000}));
/**
 * 3.处理POST 
 */
server.use(bodyParser.urlencoded({extended:false}));
server.use(multer({dest:'./cache/'}).any());

/* 
 * 4. 配置模板
 */ 
// 输出什么东西
server.set('view engine','html');
// 模板位置
server.set('views',__dirname+'/view');
// 哪种模板引擎
server.engine('html',consolidate.ejs);

// 接受用户请求
server.get("/index",function (req,res) {
    res.render('1.ejs',{user:{name:"kui"}});
})

/**
 * 4. 静态数据
 */
server.use(exStatic('./www'));